﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMS.HelperClasses;
using WHMS.HelperClasses;
using Microsoft.Reporting.WinForms;
using System.Reflection;

namespace WMS.Reports
{	
	public partial class StoreBalanceWithSpecificEnd : Form
	{
        public int selectedStoreID;

		public StoreBalanceWithSpecificEnd()
		{
			InitializeComponent();
		}

        private void StoreBalanceWithSpecificEnd_Load(object sender, EventArgs e)
		{
			//FormsHelper.LoadComboBox(StoresDDL, StoreFields.Id, StoreFields.Name, (x, y) => DALHelper.GetDynamicList(x, y, null));

			new FormsHelper().DisableReportExportToWord(this.reportViewer1);
		}


		private void RunBtn_Click(object sender, EventArgs e)
		{
			bindingSource1.DataSource = Business.GetStoreBalance(selectedStoreID);
            var storeCode = (string)DALHelper.GetValue(StoreFields.Code, StoreFields.Id, selectedStoreID);

			this.reportViewer1.LocalReport.DataSources.Clear();
			this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", bindingSource1));
			this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreName", lblStoreName.Text));
			this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreCode", storeCode));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreCode", storeCode));

			this.reportViewer1.RefreshReport();		
		}

        //private int GetSelectedStoreId()
        //{
        //    return (int)((System.Data.DataRowView)(StoresDDL.SelectedItem)).Row.ItemArray[0];
        //}

        //private string GetSelectedStoreName()
        //{
        //    return (string)((System.Data.DataRowView)(StoresDDL.SelectedItem)).Row.ItemArray[1];
        //}

        private void txtStoreCode_TextChanged(object sender, EventArgs e)
        {
            DataTable DTStore=Business.GetStoreDetails(txtStoreCode.Text);
            if (DTStore.Rows.Count > 0)
            {
                selectedStoreID = Int32.Parse(DTStore.Rows[0][0].ToString());
                lblStoreName.Text = DTStore.Rows[0][2].ToString();
                btnShowReport.Enabled = true;
            }
            else
            {
                lblStoreName.Text = string.Empty;
                btnShowReport.Enabled = false;
            }
        }

        private void btnShowReport_Click(object sender, EventArgs e)
        {
            bindingSource1.DataSource = Business.GetStoreBalance(selectedStoreID,dtpStoreEndDate.Value);
            var storeCode = (string)DALHelper.GetValue(StoreFields.Code, StoreFields.Id, selectedStoreID);
            

            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", bindingSource1));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreName", lblStoreName.Text));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreCode", storeCode));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreEndDate", dtpStoreEndDate.Value.ToString()));

            this.reportViewer1.RefreshReport();	
        }

        

        private void btnSearchStore_Click(object sender, EventArgs e)
        {
            var searchForm = new fromGeneralEntityPicker("Store");
            if (searchForm.ShowDialog() == DialogResult.OK)
            {
                txtStoreCode.Text = searchForm.SelectedItemCode;

            }
        }
	}

	
}
